# !/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
===========================
@Time : 2022/11/1 0001 20:58
@Author : 测试开发工程师
@File : load_data_utils.py
@Software: PyCharm
============================
"""

import os
import yaml
import json
import csv
from last_testapi.utils.log_utils import logger


class LoadDataUtils:

    @classmethod
    def load_data_by_yaml(cls, file_name):
        with open(file_name, encoding='utf-8') as f:
            data = yaml.safe_load(f)
        logger.debug(f'读取的配置文件为{data}')
        return data

    @classmethod
    def load_data_by_json(cls, file_name):
        with open(file_name, "r", encoding='utf-8') as f:
            data_dict = json.loads(f.read())
        return list(data_dict.values())

    @classmethod
    def load_data_by_csv(cls, file_name):
        if os.path.exists(file_name):
            with open(file_name, 'r', encoding='utf-8') as f:
                d = csv.reader(f)
            return list(d)
        else:
            print('文件不存在')
            return False
